package com.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.entity.PlatformAccount;
import com.shop.entity.PlatformAccountRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * gaodo的爸爸(PlatformAccount)表数据库访问层
 *
 * @author makejava
 * @since 2020-11-29 09:57:06
 */
@Mapper
public interface PlatformAccountMapper extends BaseMapper<PlatformAccount> {

    @Select("select balance from platform_account where user_id=#{id}")
    Double getBalance(Integer userId);

    List<PlatformAccountRecord> getWithdrawRecord(PlatformAccountRecord userId);


    @Update("update platform_account set balance=balance-#{withdrawMoney} where user_id=#{userId}")
    void updateBalance(@Param("userId") Integer userId, @Param("withdrawMoney") Double withdrawMoney);

    @Insert("insert into platform_account_record (user_id,withdraw_account,withdraw_money)" +
            "values(#{userId},#{withdrawAccount},#{withdrawMoney})")
    void addRecord(PlatformAccountRecord record);

    void checkWithdraw(PlatformAccountRecord record);

    List<PlatformAccountRecord> getAllWithdrawRecord(@Param("status") String status);
}
